package com.itheima.map;

import java.util.Comparator;
import java.util.TreeMap;

/**
 * @Author 王加鑫
 * @Date 2021/5/16 17:15
 * @Version 1.0
 */
public class MapDemo04 {
    public static void main(String[] args) {
        TreeMap<Teacher,String> map = new TreeMap<>((Comparator.comparingInt(Teacher::getAge).thenComparing(Teacher::getName)) );

          Teacher t1 = new Teacher("张三",20);
        Teacher t2 = new Teacher("李四",18);
        Teacher t3= new Teacher("王五",30);

        map.put(t1,"北京");
        map.put(t2,"上海");
        map.put(t3,"安徽");

        map.forEach( (k,v) -> System.out.println(k + "=" + v));





    }
}

class Teacher{
    private String name;
    private int age;

    public Teacher() {
    }

    public Teacher(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
